package com.youku.plugins.commonui.view.noticeCard
{
   import flash.text.TextField;
   import fl.controls.TextInput;
   import com.youku.baseUI.BasePlayerButton;
   import com.youku.utils.AssetUtil;
   import com.youku.plugins.commonui.CommonUIFont;
   import flash.events.KeyboardEvent;
   import flash.events.MouseEvent;
   import com.youku.plugins.commonui.CommonUIEvent;
   import com.youku.plugins.commonui.CommonUIConstant;
   
   public class InputPasswordCard extends BaseNoticeCard
   {
      
      public function InputPasswordCard() {
         super();
         this.init();
      }
      
      protected var _notice:TextField;
      
      protected var _passwordInput:TextInput;
      
      protected var _confirmBtn:BasePlayerButton;
      
      protected var _contactBtn:BasePlayerButton;
      
      override protected function init() : void {
         super.init();
         this._notice = AssetUtil.getTextField(false);
         this._notice.defaultTextFormat = CommonUIFont.FONT_NOTICE_TEXT_CENTER;
         this._notice.width = 400;
         this._notice.height = 30;
         this._notice.text = "";
         this._passwordInput = new TextInput();
         this._passwordInput.displayAsPassword = true;
         this._passwordInput.setStyle("upSkin",AssetUtil.getAsset("HI_bg2"));
         this._passwordInput.setStyle("textFormat",CommonUIFont.FONT_NOTICE_INPUT);
         this._passwordInput.width = 105;
         this._passwordInput.height = 24;
         this._confirmBtn = AssetUtil.getStyleButton("P_Button_OK");
         this._confirmBtn.setStyle("textFormat",CommonUIFont.FONT_INPUT_PASSWORD_CONFIRM);
         this._confirmBtn.hardOffset = -3;
         this._confirmBtn.label = "确定";
         AssetUtil.autoSizeButton(this._confirmBtn);
         this._contactBtn = AssetUtil.getStyleButton("P_Button_Cancel");
         this._contactBtn.setStyle("textFormat",CommonUIFont.FONT_INPUT_PASSWORD_CANCLE);
         this._contactBtn.hardOffset = -3;
         this._contactBtn.label = "联系上传者";
         AssetUtil.autoSizeButton(this._contactBtn);
         _card.addChild(this._notice);
         _card.addChild(this._passwordInput);
         _card.addChild(this._confirmBtn);
         _card.addChild(this._contactBtn);
         this._passwordInput.addEventListener(KeyboardEvent.KEY_DOWN,this.onKeyDown);
         this._confirmBtn.addEventListener(MouseEvent.CLICK,this.onConfirmClick);
         this._contactBtn.addEventListener(MouseEvent.CLICK,this.onContactClick);
         this.updateLayout();
      }
      
      private function onContactClick(param1:MouseEvent) : void {
         dispatchEvent(new CommonUIEvent(CommonUIEvent.NOTICE_PASSWORD_CONTACT));
      }
      
      private function onConfirmClick(param1:MouseEvent = null) : void {
         var _loc2_:String = this._passwordInput.text;
         dispatchEvent(new CommonUIEvent(CommonUIEvent.NOTICE_PASSWORD_CONFIRM,_loc2_));
      }
      
      private function onKeyDown(param1:KeyboardEvent) : void {
         if(param1.keyCode == 13)
         {
            this.onConfirmClick();
         }
      }
      
      override protected function updateLayout() : void {
         super.updateLayout();
         _noticeIcon.y = 60;
         this._notice.x = 0;
         this._notice.y = _noticeIcon.y + _noticeIcon.height + 60;
         var _loc1_:Number = this._passwordInput.width + 12 + this._confirmBtn.width + 12 + this._contactBtn.width;
         this._passwordInput.x = (_background.width - _loc1_) / 2;
         this._passwordInput.y = _noticeIcon.y + _noticeIcon.height + 120;
         this._confirmBtn.x = this._passwordInput.x + this._passwordInput.width + 12;
         this._contactBtn.x = this._confirmBtn.x + this._confirmBtn.width + 12;
         this._confirmBtn.y = this._contactBtn.y = this._passwordInput.y;
      }
      
      override public function setSize(param1:Number, param2:Number) : void {
         super.setSize(param1,param2);
         this._notice.width = CommonUIConstant.NOTICE_CARD_WIDTH;
         this.updateLayout();
      }
      
      override public function setText(param1:String) : void {
         this._notice.htmlText = param1;
      }
   }
}
